<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="__static/css/public.css" media="all">
    <script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <blockquote class="layui-elem-quote">
            <p><i class="fa fa-file-text"></i> 系统日志管理</p>
        </blockquote>

        <form class="layui-form layui-form-pane" action="" lay-filter="from1">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">员工姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" id="username" name="username" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">所属部门</label>
                    <div class="layui-input-inline">
                        <input type="text" id="department" name="department" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-primary" lay-submit
                            lay-filter="data-search-btn"><i class="layui-icon" onclick="get_ss()"></i> 搜 索
                    </button>
                </div>
            </div>
        </form>

        <table class="layui-hide" id="currentTableId1" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="toolbar">
            <div class="layui-btn-container">
                <button style="display: none;" class="layui-btn layui-btn-normal layui-btn-sm data-add-btn"
                        lay-event="add"> 添加
                </button>
                <button style="display: none;" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn"
                        lay-event="delete"> 删除
                </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/man.js" charset="utf-8"></script>
<script>
    var form, table;
    layui.use(['table'], function () {
        table = layui.table, form = layui.form;
        //用户数据列表
        table.render({
            elem: '#currentTableId1',//输入页面输入框
            url: '{:url("/Manage/users/t/json")}',
            method: 'post',//模糊查询姓名乱码解决
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            id: 'userTable',
            page: true,
            limit: 30,
            skin: 'line',
            cols: [[
                {field: 'id', width: 80, align: 'center', title: '#'},
                {field: 'role_name', width: 80, title: '角色',width:100},
                {field: 'username', width: 120, title: '员工姓名',width:180},
                {field: 'dept_name', width: 80, title: '所属部门',width:80},
                {field: 'grade_name', width: 80, title: '职级',width:80},
                {field: 'mobile', width: 100, title: '手机号',width:180},
                {field: 'gender', width: 80, title: '性别',width:80},
                {field: 'join_time', width: 135, title: '入职时间',width:120,templet:function(d){
					return d.join_time?date("Y-m-d",d.join_time):''
                }},
                {field: 'birthday', width: 135, title: '生日',width:80,templet:function(d){
					return d.birthday?date("m-d",d.birthday):''
                }},
                {field: 'last_login_ip', width: 80, title: '登陆IP',width:180},
                {field: 'last_login_time', width: 135, title: '最后登陆时间',width:180},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]]
        });
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '__static/page/table/add.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/manage/user_edit/id/' + data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                var confirm = layer.confirm('确定删除改员工信息吗?', {
                    yes: function (id) {
                        var url = '/manage/user_del/id/' + data.id;
                        $.post("{:url('user_del')}?t=json",{id:data.id}, function (d) {
                            if (d.code == 0) {
                                layer.msg('删除成功!', {
                                    time: 500
                                });
                            } else {
                                layer.msg('删除失败，请重试!', {
                                    time: 500
                                });
                            }
                            setTimeout('window.location.reload()', 500);
                        });
                        layer.close(confirm);
                    }
                });
            }
        });
        table.on('from(data-search-btn)', function (obj) {
            var data = obj.data;

        });

    });

    //重载数据表
    //数据刷新时，触发
    function get_s(msg) {
        table.reload('testReload', {
            url: '{:url("Manage/countselect/")}',
            //where: {} //设定异步数据接口的额外参数
            //,height: 300
        });
        layer.msg(msg, {icon: 6});
    }

    function get_ss() {
        var username = $("#username").val();
        var department = $("#department").val();

        table.reload('testReload', {
            url: '{:url("Manage/countselect/")}',
            where: {username: username, department: department} //设定异步数据接口的额外参数
        });
    }
</script>
</body>
</html>
